package com.ari.xml;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XMLMessageGeneratorTest {
	public static void main(final String[] args)
			throws ParserConfigurationException, Exception {
		final DocumentBuilderFactory factory = DocumentBuilderFactory
				.newInstance();
		final DocumentBuilder docBuilder = factory.newDocumentBuilder();
		final Document doc = docBuilder.newDocument();
		final Element epp = doc.createElementNS(
				"urn:ietf:params:xml:ns:epp-1.0", "epp");
		// epp.setAttributeNS("urn:ietf:params:xml:ns:epp-1.0", "xmlns",
		// "urn:ietf:params:xml:ns:epp-1.0");
		epp.setAttribute("xmlns", "urn:ietf:params:xml:ns:epp-1.0");
		epp.setAttribute("xmlns:xsi",
				"http://www.w3.org/2001/XMLSchema-instance");
		epp.setAttribute("xsi:schemaLocation",
				"urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd");
		final Element command = doc.createElementNS(
				"urn:ietf:params:xml:ns:epp-1.0", "command");
		final Element login = doc.createElementNS(
				"urn:ietf:params:xml:ns:epp-1.0", "login");
		final Element clID = doc.createElementNS(
				"urn:ietf:params:xml:ns:epp-1.0", "clID");
		epp.appendChild(command);
		command.appendChild(login);
		login.appendChild(clID);
		clID.setTextContent("TESTUSER&lt;&gt;");

		// Printing XML
		final TransformerFactory transformerFactory = TransformerFactory
				.newInstance();
		final Transformer transformer = transformerFactory.newTransformer();
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		final DOMSource source = new DOMSource(epp);
		final StreamResult result = new StreamResult(System.out);
		transformer.transform(source, result);

		System.out.println("Done executing");
	}

}
